package com.example.sdemo.api.controller;

import com.example.sdemo.app.service.CourseService;
import com.example.sdemo.app.service.ScoreService;
import com.example.sdemo.app.service.StudentService;
import com.example.sdemo.domain.entity.Course;
import com.example.sdemo.domain.entity.Score;
import com.example.sdemo.domain.entity.Student;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/score")
public class ScoreController {
    @Resource
    ScoreService scoreService;
    @Resource
    CourseService courseService;
    @Resource
    StudentService studentService;
    @RequestMapping("/toAddScore")
    public String toAddScore(Integer id, Model model){
        List<Student> students = studentService.selectAll();
        List<Course> courses = courseService.selectAll();
        model.addAttribute("students",students);
        model.addAttribute("courses",courses);
        return "addScore";
    }
    @PostMapping("/addScore")
    public String addScore(/*@RequestBody*/ Score score){
        scoreService.insertScore(score);
        return "redirect:/student/studentList";
    }
    @PostMapping("/deleteScore/{id}")
    public Boolean delScore(@PathVariable Integer id){
        return scoreService.deleteScore(id);
    }
    @PostMapping("/updateScore")
    public Boolean updateScore(@RequestBody Score score){
        return scoreService.updateScore(score);
    }
    @PostMapping("/findScore/{id}")
    public String findScore(@PathVariable Integer id){
        return scoreService.selectScoreById(id).toString();
    }

}
